package com.ytjj.qmyx.admin.controller.supplyChain;

import com.alibaba.fastjson.JSONObject;
import com.ytjj.common.utils.HttpClientUtil;
import com.ytjj.qmyx.admin.config.SupplyApiConfig;
import com.ytjj.qmyx.admin.model.bill.request.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * 账单管理
 */
@Slf4j
@RestController
@RequestMapping("/bill")
public class BillComtroller {

    @Autowired
    private SupplyApiConfig supplyApiConfig;

    /**
     * 查询供应商账单信息
     * @param request
     * @return
     */
    @PostMapping("/banker")
    public String bill(@RequestBody BankerBillRequest request){
        return HttpClientUtil.doPostJson(supplyApiConfig.getUrl() + "/banker/bill",
                JSONObject.toJSONString(request), supplyApiConfig.getHeadsMap());
    }


    /**
     * 创建账单
     * @param request
     * @return
     */
    @PostMapping("/create")
    public String create(@RequestBody CreateBillRequest request){
        return HttpClientUtil.doPostJson(supplyApiConfig.getUrl() + "/bill/create",
                JSONObject.toJSONString(request), supplyApiConfig.getHeadsMap());
    }

    /**
     * 编辑账单
     * @param request
     * @return
     */
    @PostMapping("/edit")
    public String edit(@RequestBody EditBillRequest request){
        return HttpClientUtil.doPostJson(supplyApiConfig.getUrl() + "/bill/edit",
                JSONObject.toJSONString(request), supplyApiConfig.getHeadsMap());
    }

    /**
     * 该供应商的账单列表
     * @param request
     * @return
     */
    @PostMapping("/list")
    public String list(@RequestBody BankerBillRequest request){
        return HttpClientUtil.doPostJson(supplyApiConfig.getUrl() + "/bill/list",
                JSONObject.toJSONString(request), supplyApiConfig.getHeadsMap());
    }
    /**
     * 对账完成
     * @param billId
     * @return
     */
    @GetMapping("/success")
    public String success(@RequestParam Integer billId){
        Map<String,String> map = new HashMap<>();
        map.put("billId",billId.toString());
        return HttpClientUtil.doGet(supplyApiConfig.getUrl() + "/bill/success", map, supplyApiConfig.getHeadsMap());
    }

    /**
     * 保存打款信息
     * @param request
     * @return
     */
    @PostMapping("/savePayment")
    public String savePayment(@RequestBody BillPaymentRequest request){
        return HttpClientUtil.doPostJson(supplyApiConfig.getUrl() + "/bill/savePayment",
                JSONObject.toJSONString(request), supplyApiConfig.getHeadsMap());
    }

    /**
     * 系统对账
     * @param billId
     * @return
     */
    @GetMapping("/systemReconciliation")
    public String systemReconciliation(@RequestParam Integer billId){
        Map<String,String> map = new HashMap<>();
        map.put("billId",billId.toString());
        return HttpClientUtil.doGet(supplyApiConfig.getUrl() + "/bill/systemReconciliation", map, supplyApiConfig.getHeadsMap());
    }

    /**
     * 对账单详情
     * @param request
     * @return
     */
    @PostMapping("/getStatementDetails")
    public String getStatementDetails(@RequestBody BillOrderRequest request){
        return HttpClientUtil.doPostJson(supplyApiConfig.getUrl() + "/bill/getStatementDetails",
                JSONObject.toJSONString(request), supplyApiConfig.getHeadsMap());
    }
    /**
     * 对账单列表
     * @param request
     * @return
     */
    @PostMapping("/selectStatementList")
    public String selectStatementList(@RequestBody BillOrderRequest request){
        return HttpClientUtil.doPostJson(supplyApiConfig.getUrl() + "/bill/selectStatementList",
                JSONObject.toJSONString(request), supplyApiConfig.getHeadsMap());
    }

    /**
     * 本期账单汇总
     * @param request
     * @return
     */
    @PostMapping("/getBillSummary")
    public String getBillSummary(@RequestBody BillOrderRequest request){
        return HttpClientUtil.doPostJson(supplyApiConfig.getUrl() + "/bill/getBillSummary",
                JSONObject.toJSONString(request), supplyApiConfig.getHeadsMap());
    }

    /**
     * 账单下载
     */
    @PostMapping("/download")
    public String download(@RequestBody BillOrderRequest request){
        return HttpClientUtil.doPostJson(supplyApiConfig.getUrl() + "/bill/download",
                JSONObject.toJSONString(request), supplyApiConfig.getHeadsMap());
    }
}
